package com.cloud.common.client.spring;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.EmbeddedValueResolverAware;
import org.springframework.util.StringValueResolver;

public class FeignClientFactoryBean implements FactoryBean<Object>,EmbeddedValueResolverAware {
	private Class<?> interfaceClass;
	private StringValueResolver resolver;
	public Class<?> getInterfaceClass() {
		return interfaceClass;
	}

	public void setInterfaceClass(Class<?> interfaceClass) {
		this.interfaceClass = interfaceClass;
	}

	@Override
	public Object getObject() throws Exception {
		String cloudRegisteryAddress=resolver.resolveStringValue("${cloud.registery.address}");
		return new FeignClientProxy(interfaceClass,cloudRegisteryAddress).getMapper();
	}

	@Override
	public Class<?> getObjectType() {
		return interfaceClass;
	}

	@Override
	public boolean isSingleton() {
		return true;
	}

	@Override
	public void setEmbeddedValueResolver(StringValueResolver resolver) {
		this.resolver = resolver;
	}
}